package com.example.demo.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 统一登录处理
     */
    @RequestMapping("/getuser")
    public String getUser() {
        System.out.println("执行了 getUser()");
        return "get user";
    }
    @RequestMapping("/login")
    public String login() {
        System.out.println("执行了 login()");
        return "login";
    }
    @RequestMapping("/reg")
    public String reg() {
        System.out.println("执行了 reg()");
        return "reg";
    }

    /**
     *  统一异常处理
     */
    @RequestMapping("/err")
    public String error() {
        Object object = null;
        object.hashCode();

        System.out.println("执行了 error()");
        return "error";
    }
    @RequestMapping("/err2")
    public String error2() {
        int num = 10 / 0;

        System.out.println("执行了 error2()");
        return "error2";
    }

    /**
     *  统一数据格式返回
     */
    @RequestMapping("/getnum")
    public Integer getNumber() {
        return new Random().nextInt(100);
    }

}
